{assign var="articleTitle" value=""}
{assign var="articleUrl" value=""}
{assign var="articleBody" value=""}
{assign var="articleDate" value=$datetime_now}
{assign var="articlePublished" value="no"}
{assign var="articleKeyword" value=""}

{if $view=="category" && $action=="edit"}
	{assign var="articleTitle" value=$item.name}
	{assign var="articleUrl" value=$item.url}
	{assign var="articleBody" value=$item.body}
{/if}
{if $view=="article" && $action=="edit"}
	{assign var="articleTitle" value=$item.title}
	{assign var="articleUrl" value=$item.url}
	{assign var="articleBody" value=$item.body}
	{assign var="articleDate" value=$item.date}
	{assign var="articleKeyword" value=$item.keyword}
	{if $item.published==1}
		{assign var="articlePublished" value="yes"}
	{/if}
{/if}

{if $action == "edit"}
<form name="editor" method="post" action="?view={$view}&action=edit&item={$item_name}">
{else}
<form name="editor" method="post" action="?view={$view}&action=edit">
{/if}

	<div id="adminEditor">
		<div id="adminEditorHeader">
			<table cellpadding="0" cellspacing="3">
				<tr>
					<td><label for="articleTitle"><b>Titel:</b> </label></td>
					<td><input class="articleField" type="text" id="articleTitle"
						name="articleTitle" value="{$articleTitle}" /></td>
					<td><label for="articleUrl"><b>Url:</b> </label></td>
					<td><input class="articleField" type="text" id="articleUrl"
						name="articleUrl" value="{$articleUrl}" /></td>
						
					{if $view=="article"}
						<td><label for="articleDate"><b>Datum:</b> </label></td>
						<td><input class="articleField" type="text" id="articleDate"
							name="articleDate" value="{$articleDate|date_format:"%d.%m.%Y %H:%M"}" /></td>
						<td>
							{if $articlePublished=="yes"}
								<input type="checkbox" id="articlePublished"
										name="articlePublished" checked="checked" />
							{else}
								<input type="checkbox" id="articlePublished"
										name="articlePublished" />					
							{/if}
						</td>
						<td><label for="articlePublished"><b>Freigabe erteilt</b> </label></td>
					{/if}
				</tr>
			</table>
			<div style="clear: both"></div>
		</div>
		<!-- editor -->
		{if $view=="category"}
			<textarea name="articleBody" id="articleBody" style="width:800px; height: 370px;">{$articleBody|stripslashes}</textarea>
		{/if}
		{if $view=="article"}
			<div id="adminEditorCategoryList">
				{if $action=="edit"}
					<div class="articlePreviewLink" onclick="javascript:opener.location.href='/p/{$articleUrl}.html';">
						Artikelvorschau
					</div>
				{/if}
				<table cellpadding="5" cellspacing="0">
				<tr>
					<td><b>Schlagwort</b></td>
				</tr><tr>
					<td>
						<input type="text" id="articleKeyword" name="articleKeyword" value="{$articleKeyword}" />
					</td>
				</tr>
				</table>
				<br />
				<table cellpadding="5" cellspacing="0">
				<tr>
					<td></td>
					<td><b>Kategorien</b></td>
				</tr>
				{foreach from=$category_list item=category_item}
					<tr>
						<td>
							{if $action == "edit"}
								{assign var="categoryHasArticle" value="false"}
								{foreach from=$article_category_list item=article_category_item}
									{if $article_category_item.article_url == $articleUrl 
										&& $article_category_item.category_url == $category_item.url}
										{assign var="categoryHasArticle" value="true"}
									{/if}
								{/foreach}
								{if $categoryHasArticle == "true"}
									<input type="checkbox" id="articleCategory_{$category_item.url}" 
										name="articleCategory_{$category_item.url}" checked="checked" />							
								{else}
									<input type="checkbox" id="articleCategory_{$category_item.url}" 
										name="articleCategory_{$category_item.url}" />								
								{/if}
							{else}
								<input type="checkbox" id="articleCategory_{$category_item.url}" 
									name="articleCategory_{$category_item.url}" />
							{/if}
						</td>
						<td>
							<label for="articleCategory_{$category_item.url}">
								{$category_item.name}
							</label>
						</td>
					</tr>
				{/foreach}
				</table>
			</div>
			<textarea name="articleBody" id="articleBody" style="width:650px; height: 370px;">{$articleBody|stripslashes}</textarea>
		{/if}
	</div>
</form>
